home *** CD-ROM | disk | FTP | other *** search
- Path: pacbell.com!well!usenet
- From: rickyarm@well.com ()
- Newsgroups: comp.lang.c
- Subject: I need some help re: scanf, getchar
- Date: Sat, 17 Feb 1996 03:14:08 GMT
- Organization: The Whole Earth 'Lectronic Link, Sausalito, CA
- Message-ID: <4g3h6g$9ri@nkosi.well.com>
- NNTP-Posting-Host: sr-tty5-ppp.well.com
- X-Newsreader: Forte Free Agent v0.71
-
- Hello there,
-
- My name is Rick Armanino and I am having some trouble with my program
- for a class that I am taking. Can someone help with these problems??
-
- 1. the first time through the do/while loop runs smooth; user enters
- 1 for entering new accounts finishes then the loop displays the menu
- again but getchar() does not wait for the users input on the second
- time around and goes straight to the default of the switch. WHY AND
- WHERE IS GETCHAR GETING ITS INPUT FROM?
-
- 2. Inside the first choice of entering new accounts the user is
- prompt if there are more accounts to be entered. Inorder to make the
- do/while loop function I had to read something into a garbage varible.
- WHY IS THIS HAPPENING??
-
- THANKS FOR ANY ADVICE---rickyarm@well.com
- ------------------------------------------------------------------------------------------------
-
- do{ /*menu part of the program prompts user to choose one of 5
- options responce is placed into 'ch' */
-
- printf("\tEnter Selection: ");
- ch = getchar(); /*WHERE IS GETCHAR() GETTING ITS INPUT FROM ON THE
- SECOND TIME AROUND IN THE LOOP*/
- printf("the value of 'ch' is: ");
- putchar(ch);
- printf("\n");
-
- switch(ch) {
- case '1':/*begining of entering a new account*/
- do {
- bufnode = GetUserInput();
-
- if (!root)
- root = InsertSort(root, root, bufnode);
- else
- InsertSort(root, root, bufnode);
-
- printf("\n\t\tAre there more accounts to be entered?\n");
- scanf("%c", &garbage);
- scanf("%c", &ans); /*THERE IS SOMETHING STILL IN THE BUFFER? BECAUSE
- THE ONLY WAY THAT THIS WHILE LOOP CONTINUES IS IF SOMETHING IS READ
- INTO GARBAGE ANY SUGGESTTIONS WOULD BE OF GREAT HELP*/
-
- }while(ans == 'y');
-
-
- if (root)
- Print_Inorder(root);
- break; /*end of entering new account option*/
-
- case '2': /*Search for an account option*/
- printf("Name of the account you want to search for: \n");
- scanf("%s", keylastname);
-
- temp = root;
- temp = Search(root, keylastname);
-
- if (temp != NULL)
- printf("the acount that you found is: %s\n", temp->lastname);
- else
- printf("No account was found by that name\n");
- break; /*end of search option*/
-
- case '3': /*make a deposit*/
-
- case '4': /*make a withdrawal*/
-
- default: /*exit the system*/
- endsys = 1;
- printf("the end of the system\n");
- break;
- }/*end of swich statement*/
- }while (!endsys);
- }
-
-